<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
</style>
<script type="text/javascript">
    var codeDataDataGrid;
    $(function() {
        codeDataDataGrid = $('#codeDataDataGrid').datagrid({
            url : '${path}/code/codeData/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            columns : [ [
                {
                width : '100',
                title : 'id',
                field : 'id'
                ,hidden : true
            },
                {
                width : '100',
                title : '编码',
                field : 'code'
            },
                {
                width : '100',
                title : '名称',
                field : 'name'
            },
                {
                width : '100',
                title : '类别',
                field : 'category'
            },
                {
                width : '100',
                title : '类别名称',
                field : 'categoryName'
            },
                {
                width : '100',
                title : '备注',
                field : 'remark'
            },
            ]],
             frozenColumns : [ [{
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="codeData-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editCodeDataFun(\'{0}\');" >编辑</a>', row.id);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="codeData-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteCodeDataFun(\'{0}\');" >删除</a>', row.id);
                      str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="codeData-easyui-linkbutton-view" data-options="plain:true,iconCls:\'fi-magnifying-glass\'" onclick="viewCodeDataFun(\'{0}\');" >查看</a>', row.id);
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.codeData-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.codeData-easyui-linkbutton-del').linkbutton({text:'删除'});
                $('.codeData-easyui-linkbutton-view').linkbutton({text:'查看'});
            }, 
            toolbar : '#codeDataToolbar'
        });
    });

    function addCodeDataFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 300,
            href : '${path}/code/codeData/toAdd',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = codeDataDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#codeDataAddForm');
                    f.submit();
                }
            } ]
        });
    }

     function editCodeDataFun(id) {
        if (id == undefined) {
            var rows = codeDataDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            codeDataDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 500,
            height : 300,
            href : '${path}/code/codeData/toEdit/' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = codeDataDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#codeDataEditForm');
                    f.submit();
                }
            } ]
        });
    }

    function deleteCodeDataFun(id) {
        if (id == undefined) {//点击右键菜单才会触发这个
            var rows = codeDataDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            codeDataDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除吗？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path}/code/codeData/delete/'+id, {}
                , function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        codeDataDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
     function viewCodeDataFun(id) {
        if (id == undefined) {
            var rows =  codeDataDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
             codeDataDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '查看',
            width : 800,
            height : 450,
            href : '${path}/code/codeData/view/' + id,
        });
    } 
    function searchCodeDataFun() {
    	codeDataDataGrid.datagrid('load', $.serializeObject($('#searchCodeDataForm')));
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
 <div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="searchCodeDataForm">
            <table>
                <tr>
                    <th>类别:</th>
                    <td>
                    <select name='category'  class='easyui-text' id="codeDataList_category" style="width:200px;">
                    		<option value="">-请选择-</option>
                        	<c:if test="${codeCategoryList.size()>0}">
                        		<c:forEach var="codeCategory" items="${codeCategoryList}">
                        		 <option value="${codeCategory.category}">${codeCategory.categoryName}</option>
                        		</c:forEach>
                        	</c:if>
                        </select>
					</td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchCodeDataFun();">查询</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
                            <div data-options="region:'center',border:true">
        <table id="codeDataDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="codeDataToolbar" style="display: none;">
    <a onclick="addCodeDataFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
</div>
